package apis

import (
	"LazyPig/models"
	"LazyPig/pkg/res"
	"fmt"
	"github.com/gin-gonic/gin"
)

func NewRule(c *gin.Context)  {
	var rule models.Rule
	if err := c.Bind(&rule);err != nil {
		fmt.Println(err)
		return
	}
	_, err := models.NewRule(&rule)
	if err != nil {
		c.JSON(res.FailedJson(err.Error()))
		return
	}
	c.JSON(res.SuccessJson(nil))
}

func GetRuleList(c *gin.Context)  {
	rows, err := models.GetRuleList()
	if err != nil {
		c.JSON(res.FailedJson(err.Error()))
		return
	}
	c.JSON(res.SuccessJson(rows))
}

func GetRule(c *gin.Context)  {
	var id = c.Query("id")
	row, err := models.GetRule(id)
	if err != nil {
		c.JSON(res.FailedJson(err.Error()))
		return
	}
	c.JSON(res.SuccessJson(row))
}

func GetCame(c *gin.Context)  {
	var id = c.Query("id")
	rows, err := models.GetCame(id)
	if err != nil {
		c.JSON(res.FailedJson(err.Error()))
		return
	}
	c.JSON(res.SuccessJson(rows))
}

func Delete(c *gin.Context)  {
	var id = c.Query("id")
	err := models.Delete(id)
	if err != nil {
		c.JSON(res.FailedJson(err.Error()))
		return
	}
	c.JSON(res.SuccessJson(nil))
}